<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Vue中函数使用原则</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../../js/vue.js"></script>
  </head>
  <body>
    <!-- 准备好一个容器-->
    <div id="demo">
      <h1>当前的a值是：{{a}}</h1>
      <button @click="add">点我1秒后a+1</button>
    </div>

    <script type="text/javascript">
      new Vue({
        el:'#demo',
        data:{
          a:100
        },
        methods: {
          add(){
            console.log(1,this)
            setTimeout(()=>{
              console.log(2,this)
              this.a+=1
            }, 1000);
          }
        },
      })
    </script>
  </body>
</html>